import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-10-22
 * Time: 19:15
 */
public class TestDemo {
    public static int[] copyOf(int[] array){
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        return copy;
    }
    public static String myToString(int[] array){
        if (array == null) {
            return null;
        }
        String str = "[";
        for (int i = 0; i < array.length; i++) {
            str = str + array[i];
            if (i != array.length-1){
                str = str + ",";
            }
        }
        str = str + "]";
        return str;
    }
    public static void swap(int[] array){
        int left = 0;
        int right = array.length - 1;
        while (left < right) {
            //找奇数
            while (left < right && array[left] % 2 == 0) {
                left++;
            }
            //找偶数
            while (left < right && array[right] % 2 != 0) {
                right--;
            }
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
        }
    }
    public static void swap2(int[] array1,int[] array2) {
        int[] ret = new int[array1.length];
        int a = 0;
        while (a <= 4) {
            for (int i = 0; i < array1.length-1; i++) {
                int tmp = array1[i];
                array1[i] = array1[i+1];
                array1[i+1] = tmp;
            }
            for (int j = 0; j < array2.length-1; j++) {
                int tmp = array2[j];
                array2[j] = array2[j+1];
                array2[j+1] = tmp;
            }
            a++;
        }
    }
    public static void main(String[] args) {
        int[] array1 = {1,3,5,7,9};
        int[] array2 = {2,4,6,8,10};
        swap2(array1,array2);
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
    }
    public static void main3(String[] args) {
        int[] array = {3,4,5,6,8,9,7,1,10};
        swap(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        System.out.println(myToString(array));
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        int[] ret = copyOf(array);
        System.out.println(Arrays.toString(ret));
    }
}
